package com.hospital.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hospital.dao.UserInfoDAO;
import com.hospital.model.UserInfo;
import com.hospital.util.MD5;

@WebServlet("/manage/ModifyUserInfoPswdServlet")
public class ModifyUserInfoPswdServlet extends HttpServlet {

	protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		UserInfo userInfo = new UserInfo();
		userInfo.setId(Integer.parseInt(request.getParameter("id")));
		String pswd = request.getParameter("pswd");
		String md5password = MD5.MD5(pswd);
		userInfo.setPswd(md5password);
		String confirmpswd = request.getParameter("confirmpswd");
		boolean b = new UserInfoDAO().modifyPswd(userInfo);
		if(!(pswd.equals(confirmpswd))){
			request.setAttribute("rs", "修改失败，请重新操作。");
			request.getRequestDispatcher("/manage/pswd_modify.jsp").forward(request, response);
		}else{
			if(b){
				request.setAttribute("rs", "修改成功，下次登录请以新密码登录。");
				request.getRequestDispatcher("/manage/pswd_modify.jsp").forward(request, response);
			}else{
				request.setAttribute("rs", "修改失败，请重新操作。");
				request.getRequestDispatcher("/manage/pswd_modify.jsp").forward(request, response);
			}
		}
	}

}
